const app = getApp()
const{
  feedbackList
} =require('../../api/project')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page:1,
    search_key:'',
    pageSize:10,
    feedback_list:[],
    value: '',
    userInfo:null,
    finished: false
  },
  
  previewImage(e) {
    var current=e.target.dataset.imglist;
    var currentUrl = current[0];
		wx.previewImage({
		  	current: currentUrl, // 当前显示图片的http链接
		  	urls: current // 需要预览的图片http链接列表
		})
  },
  onClickToReleaseTask() {
    wx.navigateTo({
      url: `/pages/canvas/index?pn=&id=0&task_id=0&is_desc=false&do_type=3`,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo:app.userInfo,
      isLogin:app.isLogin
    })
    this.init()
  },
  onChange(event){
    this.data.page=1
    this.data.feedback_list=[]
    this.data.search_key=event.detail
    console.log("search:",this.data.search_key)

    this.init()

    //this.init()
  },
  init(){
    wx.showLoading({
      title: '数据加载中~',
    })
    feedbackList({page:this.data.page,pageSize:this.data.pageSize,maintainid:this.data.search_key}).then(res=>{
      let templateList=res.data.list
      if(!templateList.length>0){
        this.data.finished=true
      }
      if(templateList && templateList.length){
        this.data.feedback_list=[...this.data.feedback_list,...templateList]
      }
      this.setData({
        feedback_list:this.data.feedback_list ||[]
      })
      wx.hideLoading({
        complete: (res) => {},
      })
      wx.hideNavigationBarLoading(); //完成停止加载图标
      wx.stopPullDownRefresh();
    })
  },
  projectDetailPage(e){
    var pn=e.currentTarget.dataset.pn;
    var project_id=e.currentTarget.dataset.project_id;
    wx.navigateTo({
      url: `/pages/projectDetail/index?pn=${pn}&id=${project_id}`,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
      this.data.page=1
      this.data.feedback_list=[]
      this.data.finished=false
      this.init()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(!this.data.finished){

      this.data.page=parseInt(this.data.page+1)
      this.init()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})